<?php defined("MAIN_DIR") or die("No direct access");

$business_id = UV::readInt($route->getPath(4));
if ($business_id == "") {
	to("/$c_name/credits/");
}

$business_res = mysql_query("select `C`.*,`B`.`city_id`,`B`.`link`,`B`.`name` as `bank_name` from `business` as `C`,`bank` as `B` where `business_id` = '$business_id' and `C`.`bank_id` = `B`.`bank_id` limit 1");

if (mysql_num_rows($business_res) == 0) {
	to("/$c_name/credits/");
}

$business_row = mysql_fetch_array($business_res);
$city_row = mysql_fetch_array(mysql_query("select * from `city` where `city_id` = '$business_row[city_id]' limit 1"));
if ($_SESSION['city'] != $business_row['city_id']) {
	to("/$city_row[path]/credits/business.php?business_id=$business_row[business_id]");
}

$head_title = "Кредит ".$business_row['name']." - «Банки России»";

require_once APP.HEADFILE;
?>
<script type="text/javascript" src="/files/js/bank_list.js"></script>
<h1>Кредит <?php echo $business_row['name']?></h1>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
		<td align="left" valign="top" class="banki_main_col">
			<div id="credit_bank">Банк: <a href="<?php echo "/$c_name";?>/banks/<?php echo $business_row['link'].".html"; ?>"><?php
				echo $business_row['bank_name'];
			?></a></div>
			<table width="500" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td class="credit_table_item"><strong>Валюта</strong></td>
					<td class="credit_table_item"><strong>Сумма</strong></td>
					<td class="credit_table_item"><strong>Срок</strong>, годы</td>
					<td class="credit_table_item"><strong>Ставка</strong>, %</td>
				</tr><?php
				$cc_res = mysql_query("select * from `credit_currency` where `credit_id` = '$business_id' and `type` = '5'");
				while ($cc_row = mysql_fetch_array($cc_res))
				{
					?><tr>
						<td valign="top" class="credit_table_item"><em><?php
							echo $cc_row['currency'];
						?></em></td>
						<td valign="top" class="credit_table_item">от <?php
							echo getValue($cc_row['sum_low']); ?><br />до <?php echo getValue($cc_row['sum_high']);
						?></td>
						<td valign="top" class="credit_table_item">от <?php
							echo $cc_row['period_low']; ?><br />до <?php echo $cc_row['period_high'];
						?></td>
						<td valign="top" class="credit_table_item">от <?php
							echo $cc_row['rate_low'];?><br />до <?php echo $cc_row['rate_high'];
						?></td>
					</tr><?php
				}
			?></table>
			<div class="credit_second_table">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<?php
					if ($business_row['credit_purpose'] != "") {
						?><tr>
							<td width="47%" align="left" valign="top" class="credit_second_table_item">Цель кредита</td>
							<td width="53%" align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $business_row['credit_purpose'];
							?></td>
						</tr><?php
					}
					if ($business_row['postponement'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Отсрочка начала погашения</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $business_row['postponement'];
							?></td>
						</tr><?php
					}
					if ($business_row['request_reriod'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Срок рассмотрения заявки</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo word_ending($business_row['request_reriod'],"день","дня","дней");
							?></td>
						</tr><?php
					}
					if ($business_row['material_security'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Материальное обеспечение</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $business_row['material_security'];
							?></td>
						</tr><?php
					}
					if ($business_row['surety'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Поручительство</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $business_row['surety'];
							?></td>
						</tr><?php
					}
					if ($business_row['output_form'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Форма выдачи</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $business_row['output_form'];
							?></td>
						</tr><?php
					}
					if ($business_row['repayment_mode'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Порядок погашения</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $business_row['repayment_mode'];
							?></td>
						</tr><?php
					}
					if ($business_row['business_age']) {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Срок существования бизнеса</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo word_ending($business_row['business_age'],"месяц","месяца","месяцев");
							?></td>
						</tr><?php
					}
					?>
				</table>
			</div>
		</td>
		<td width="159" align="left" valign="top"><?php
			require_once APP."rating_column.php";
			require_once APP."vacancy_column.php";
		?></td>
	</tr>
</table>
<div class="inside_block">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr valign='top'>
			<td width="344" class="inside_info"><?php
				require_once APP."bank_list.php";
				require_once APP."currency_rates.php";
			?></td>
			<td width="646"><?php
				echo "<h2>$business_row[name]</h2>";
				if ($business_row['info'] != "")
					echo "<p>".getRichText($business_row['info'])."</p>";
				else
				{
					$info = mysql_fetch_array(mysql_query("select * from `info` where `info_id` = '17' limit 1"));
					$text = getRichText($info['text']);
					echo "<p>$text</p>";
				}
			?></td>
		</tr>
	</table>
</div>
<?php require_once APP.FOOTERFILE; ?>